$(function(){
	
	    $(".edita").click(function(){
	        //获取当前点击
			
	           trobj= $(this).parents('tr');
	           pid = trobj.find("td:eq(0)").text()
			   petimgtd = trobj.find("td:eq(1)")
	           pname = trobj.find("td:eq(2)").text()
	           oname = trobj.find("td:eq(3)").text()
	           address= trobj.find("td:eq(4)").text()
	           ability = trobj.find("td:eq(5)").text()
	           pclass = trobj.find("td:eq(6)").text()
			   
			   msgtd = trobj.find("td:eq(7)")
			   petmsg = msgtd.find("input:eq(0)").val()
			   pet_his = msgtd.find("input:eq(1)").val()
			   pet_fit = msgtd.find("input:eq(2)").val()
			   
			   datatd = trobj.find("td:eq(9)")
			   bueaty = datatd.find("input:eq(0)").val()
			   pet_clingy = datatd.find("input:eq(1)").val()
			   pet_kind = datatd.find("input:eq(2)").val()
			   pet_smart = datatd.find("input:eq(3)").val()
			   pet_honest = datatd.find("input:eq(4)").val()
			
			var petimg = petimgtd.find('img')
			var petimg_copy= petimg.clone()
			petimg_copy.css('width','45%')
			petimg_copy.addClass('replaceimg') //添加class类名
			var imgshow = $('#imgContaineru2').find('img')
			  imgshow.replaceWith(petimg_copy)
			   $('#imgContaineru2').css('display','block')
		
	           $('#pidu').val(pid)
	           $('#pnameu').val(pname)
	           $('#onameu').val(oname)
	           $('#addressu').val(address)
	           $('#abilityu').val(ability)
	           $('#pclassu').val(pclass)
			   $('#petmsgu').val(petmsg)
			   $('#pet_hisu').val(pet_his)
			   $('#pet_fitu').val(pet_fit)
			   $('#bueatyu').val(bueaty)
			   $('#pet_clingyu').val(pet_clingy)
			   $('#pet_kindu').val(pet_kind)
			   $('#pet_smartu').val(pet_smart)
			   $('#pet_honestu').val(pet_honest)
			   show_update_img()
	    })
		
	
	                $("#submitbut2").click(function(){
	                        $("#modbut").click()
	                });
								
	})
	 
	
/* 更换宠物图片 */	
	var fileInput = document.getElementById('petimgu');
	
	  function showImgu(obj) {
	    var files = obj.files
	    document.getElementById("imgContaineru").innerHTML = getImgsByUrlu(files)
	  }
		 //获取图像元素
	  function getImgsByUrlu(files) {
	    var elements = ''
		
	    for (var i = 0; i < files.length; i++) {
	      var url = window.URL.createObjectURL(files[i])
	      elements += "<img src='" + url + "' style='width: 55%;' class='changeimg'/>"
	    }
	    return elements
	  }
		//清除修改图片
					 function clearupdate(){
						 var addimg = document.getElementsByClassName('changeimg')
						 $('#imgContaineru2').css('display','none')
						 try{
							 addimg.item(addimg).remove()
							
						 }catch(err){ 
							 console.log()
						 }
						 
					  fileInput.value = null;  
	                                 }
//展示添加和更新图片
	function show_update_img(){
		 // var imgreplace= document.getElementById('imgreplace')
		var myModal2 = document.getElementById('myModal2')
			
		$('.btn-file').click( function(){
			const eventshow = myModal2.addEventListener('mousemove',(event)=>{
				try{    var changeimg= document.getElementsByClassName('changeimg')
				      flagchange =  changeimg[0].TEXT_NODE
						  // alert(changeimg)
						  if(flagchange == 3){$('#imgContaineru2').css('display','none')}
						  else{
							  $('#imgContaineru2').css('display','block')
						  }
								 }catch(err){
								console.log()
							}	
			})//mousemove
		})//click   
	} //show_update_img()结束

//判断增删改查的信息，用弹出框显示信息
   function showDropdown() {  
				  
                  var dropdown = document.querySelector('.dropshowdown'); 
				   //获取修改增加后的提示信息
				  try{ 
					  var flagmy = document.getElementById('showdownbox').value;
				  }catch(err){}
				
				 var res_arg = document.getElementById('res_arg').value;
			   
				if(res_arg == '删除成功!'){
					dropdown.style.display = 'block';
						setTimeout(() => {  
						    dropdown.style.display = 'none';  
							res_arg.value =null
						}, 2000); 	
				}  
				
				switch(flagmy){
				 case('宠物信息添加成功!'):
					 dropdown.style.display = 'block';
					 	setTimeout(() => {  
					 	    dropdown.style.display = 'none';  
					 		flagmy.value =null
					 	}, 2000); 
				 case('宠物信息添加失败!可能为宠物名重复'):	
				     dropdown.style.display = 'block';
				     	setTimeout(() => {  
				     	    dropdown.style.display = 'none';  
							flagmy.value =null
				     	}, 2000); 
				case('宠物信息修改成功!'):
				    dropdown.style.display = 'block';
				    	setTimeout(() => {  
				    	    dropdown.style.display = 'none';  
							flagmy.value =null
				    	}, 2000); 	
				case('宠物信息修改失败!可能为宠物名重复'):
				    dropdown.style.display = 'block';
				    	setTimeout(() => {  
				    	    dropdown.style.display = 'none';  
							flagmy.value =null
				    	}, 2000); 	
					
				} /* switch结束*/
				try{
					if(flagmy.indexOf("爬取")>=0){
					dropdown.style.display = 'block';
						setTimeout(() => {  
						    dropdown.style.display = 'none';  
							flagmy.value =null
						}, 2000); 	
				}}catch(err){
					
				}
				
				
              }/*showDropdown()结束*/ 
showDropdown()